package cn.tips.dmp.system.assist.log.service.impl;

import cn.tips.dmp.supports.jpa.PageParamsDTO;
import cn.tips.dmp.supports.jpa.SortParamsDTO;
import cn.tips.dmp.system.assist.log.dto.SystemAccessLogParamsDto;
import cn.tips.dmp.system.assist.log.po.SystemAccessLogPo;
import cn.tips.dmp.system.assist.log.repository.SystemAccessLogRepository;
import cn.tips.dmp.system.assist.log.service.SystemAccessLogService;
import com.querydsl.jpa.impl.JPAQueryFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class SystemAccessLogServiceImpl implements SystemAccessLogService {

    @Autowired
    private SystemAccessLogRepository systemAccessLogrepository;

    @Autowired
    JPAQueryFactory jpaQueryFactory;


    @Override
    public Page<SystemAccessLogPo> readAllByPage(SystemAccessLogParamsDto searchParamsDto, PageParamsDTO pageParamsDto, SortParamsDTO sortParamsDto) {
//        QSystemAccessLogPo qSystemAccessLogPo = QSystemAccessLogPo.systemAccessLogPo;
//
//        // 开启谓语查询条件
//        Predicate predicate = qSystemAccessLogPo.id.isNotNull();
//
//        // 排序
//        Sort sort = sortParamsDto.getSort();
//        if (null == sort) {
//            sort = Sort.by(new Sort.Order(Sort.Direction.DESC, "createTime"), new Sort.Order(Sort.Direction.DESC, "createTime"));
//        }
//
//        // 执行返回
//        Pageable pageable = pageParamsDto.getPageableWithSort(sort);
//
//        return systemAccessLogrepository.findAll(predicate, pageable);


        return null;
    }

    @Override
    public List<SystemAccessLogPo> readAll(SystemAccessLogParamsDto searchParamsDto, PageParamsDTO pageDto, SortParamsDTO sortDto) {
//        QSystemAccessLogPo qSystemAccessLogPo = QSystemAccessLogPo.systemAccessLogPo;
//
//        // 开启谓语查询条件
//        Predicate predicate = qSystemAccessLogPo.id.isNotNull();
//
//        // 排序
//        Sort sort = sortDto.getSort();
//        if (null == sort) {
//            sort = Sort.by(new Sort.Order(Sort.Direction.DESC, "createTime"), new Sort.Order(Sort.Direction.DESC, "uploadTime"));
//        }
//        return Lists.newArrayList(systemAccessLogrepository.findAll(predicate, sort).iterator());

        return null;
    }

    @Override
    public SystemAccessLogPo readById(Long id) {
        return systemAccessLogrepository.findById(id).orElse(null);
    }

    @Override
    public void add(SystemAccessLogPo excepLog) {
        systemAccessLogrepository.save(excepLog);
    }

}
